﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace CryptoLogo
{
	class ImageGenerator
	{
		public Image GenerateImage()
		{
			Bitmap image = new Bitmap(800, 600);
			Graphics grafx = Graphics.FromImage(image);
			Pen pen = new Pen(Color.Black);

			List<PointF> pointsList = new List<PointF>();
			pointsList.Add(new PointF(0, this.VerticalalOffset));
			pointsList.Add(new PointF(this.HorizontalOffset, 0));
			pointsList.Add(new PointF(2 * this.HorizontalOffset, this.VerticalalOffset));
			pointsList.Add(new PointF(2 * this.HorizontalOffset, this.VerticalalOffset + this.EdgeLength));
			pointsList.Add(new PointF(this.HorizontalOffset, 2 * this.VerticalalOffset + this.EdgeLength));
			pointsList.Add(new PointF(0, this.VerticalalOffset + this.EdgeLength));
			pointsList.Add(new PointF(this.HorizontalOffset, 2 * this.VerticalalOffset));

			PointF[] points = pointsList.ToArray();

			//	Shift all of these points
			for (int i = 0; i < points.Length; i++)
			{
				points[i].X += this.Origin.X;
				points[i].Y += this.Origin.Y;
			}

			grafx.DrawLine(pen, points[0], points[1]);
			grafx.DrawLine(pen, points[1], points[2]);
			grafx.DrawLine(pen, points[2], points[3]);
			grafx.DrawLine(pen, points[3], points[4]);
			grafx.DrawLine(pen, points[4], points[5]);
			grafx.DrawLine(pen, points[5], points[0]);
			grafx.DrawLine(pen, points[0], points[6]);
			grafx.DrawLine(pen, points[2], points[6]);
			grafx.DrawLine(pen, points[4], points[6]);

			return image;
		}

		private PointF origin;
		public PointF Origin
		{
			get
			{
				return origin;
			}
			set
			{
				this.origin = value;
			}
		}

		private float edgeLength;
		public float EdgeLength
		{
			get
			{
				return edgeLength;
			}
			set
			{
				edgeLength = value;
			}
		}

		private float alpha;
		public float Alpha
		{
			get
			{
				return alpha;
			}
			set
			{
				this.alpha = value;
			}
		}

		private float horizontalOffset = -1.0f;
		private float HorizontalOffset
		{
			get
			{
				if (horizontalOffset == -1.0f)
				{
					horizontalOffset = (float)(Math.Abs(EdgeLength * Math.Cos((double)this.Alpha)));
				}

				return horizontalOffset;
			}
		}

		private float verticalalOffset = -1.0f;
		private float VerticalalOffset
		{
			get
			{
				if (verticalalOffset == -1.0)
				{
					verticalalOffset = (float)(Math.Abs(EdgeLength * Math.Sin((double)this.Alpha)));
				}

				return verticalalOffset;
			}
		}
	}
}
